package cn.mifengkong.appcommon.webview.jshandler;

import android.text.TextUtils;

import com.mifengkong.frtools.jsbridge.CallBackFunction;
import com.mifengkong.frtools.jsbridge.JsHandler;

import org.json.JSONException;
import org.json.JSONObject;

import cn.mifengkong.appcommon.webview.listener.JsBridgeCallBackListener;

/**
 * Created by jiang on 2018/3/6
 *
 * @author fengrong
 *         调起小程序
 */

public class LuanchMiniProgramHandler implements JsHandler {

    private JsBridgeCallBackListener mListener;

    public LuanchMiniProgramHandler(JsBridgeCallBackListener listener) {
        mListener = listener;
    }

    @Override
    public void OnHandler(String handlerName, String responseData, CallBackFunction function) {
        try {
            JSONObject responseDataJO = new JSONObject(responseData);
            String miniProgramId = responseDataJO.getString("name");
            String path = responseDataJO.getString("path");
            int type = responseDataJO.getInt("type");
            if (!TextUtils.isEmpty(miniProgramId) && mListener != null) {
                mListener.luanchMiniProgram(miniProgramId, path, type);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

}
